<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #box {
            width: 300px;
            height: 300px;
            border: 1px solid #000000;
            margin-top: 30px;
        }
    </style>
</head>

<body>
    <button id="btn">点击</button>
    <div id="box"></div>
    <script src="./js/utils.js"></script>
    <script>
        // 方法一：
        btn.onclick = function () {
            var box = document.getElementById('box');
            var str = '#';
            var arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'a', 'b', 'c', 'd', 'e', 'f', 'A', 'B', 'C', 'D', 'E','F']
            var random = 0;
            for (i = 0; i < 6; i++) {
                random = parseInt(Math.random() * 16);
                str += arr[random];
            }
            box.style.backgroundColor = str;
        }
        // 方法二：
        // btn.onclick = function () {
        //     var box = document.getElementById('box');
        //     box.style.backgroundColor = '#' + Math.floor(Math.random() * 256).toString(10);
        // }

        //方法三：
        // btn.onclick = function () {
        //     var box = document.getElementById('box');
        //     console.log('#' + randomNum(100000, 999999).toString(16))
        //     box.style.backgroundColor = '#' + randomNum(1000000, 9999999).toString(16);
        // }
    </script>
</body>

</html>